package com.ph.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("uri:{}",request.getRequestURI());
        try {
            String token = request.getHeader("token");
            SecurityUtils.getSubject().login(new UUIDToken(token));
        }catch (Exception e){
            e.printStackTrace();
        }
        return true;
    }
}
